/********************************************************************************
 * @Author: Zhenzhou Liu
 * @Date: 2024-12-29
 * @Description: Cg图论练习之有向图所有点对联通性判断（Floyd-Warshall）
 *******************************************************************************/
#include <iostream>
#include <vector>

using namespace std;

void floydWarshall(vector<vector<bool>> &reachable,  int n) {
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (reachable[i][k] && reachable[k][j]) {
                    reachable[i][j] = true;
                }
            }
        }
    }
}

int main()  {
    int n, m, q;
    cin>>n>>m>>q;
    vector<vector<bool>> reachable(n + 1, vector<bool>(n + 1, false));

    for(int i = 1; i <= n; i++)
        reachable[i][i] = true;
    int x, y;
    for(int j = 1; j <= m; j++) {
        cin >> x >> y;
        reachable[x][y] = true;
    }
    floydWarshall(reachable, n);

    vector<int> res;
    for (int i = 0; i < q; ++i) {
        cin >> x >> y;
        res.push_back(reachable[x][y] ? 1 : 0);
    }
    for (int val : res)
        cout << val << endl;
    return 0;
}


/* Test Case1
3 2 3
1 2
2 3
1 3
3 1
2 1
*/
